﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace de.wolfmarco.pas.Shared.Helper
{
    public static class UserInterfaceHelper
    {
        /// <summary>
        /// Returns a window if the object or one of the parents is a window.
        /// Returns the first window, which is found in the parent hierarchy.
        /// If no window is found, null is returned.
        /// </summary>
        /// <param name="arg">Should be a System.Windows.FrameworkElement</param>
        /// <returns>System.Windows.Window</returns>
        public static Window GetWindow( object arg )
        {
            FrameworkElement element = arg as FrameworkElement;
            if( element == null )
                return null;
            else if( element is Window )
                return element as Window;
            else
                return GetWindow( element.Parent );
        }
    }
}
